package com.ysg.utils;

import android.app.Activity;
import android.content.Context;

import com.github.gzuliyujiang.wheelpicker.DatePicker;
import com.github.gzuliyujiang.wheelpicker.DatimePicker;
import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener;
import com.github.gzuliyujiang.wheelpicker.contract.OnDatimePickedListener;
import com.github.gzuliyujiang.wheelpicker.entity.DateEntity;
import com.github.gzuliyujiang.wheelpicker.widget.DateWheelLayout;
import com.ysg.callback.StringCallback;
import com.ysg.enums.NoDiamondEnum;
import com.ysg.http.data.entity.expression.ExpressionEntity;
import com.ysg.http.data.entity.mine.SignResult;
import com.ysg.http.data.entity.mine.VersionEntity;
import com.ysg.http.data.entity.ticket.TicketPriceEntity;
import com.ysg.http.data.entity.user.UserResult;
import com.ysg.widget.dialog.AvatarEditDialog;
import com.ysg.widget.dialog.CallDialog;
import com.ysg.widget.dialog.ConfirmDialog;
import com.ysg.widget.dialog.DiamondRechargeDialog;
import com.ysg.widget.dialog.ExpressionDialog;
import com.ysg.widget.dialog.GiftDialog;
import com.ysg.widget.dialog.GuardDialog;
import com.ysg.widget.dialog.IntimacyGiftDialog;
import com.ysg.widget.dialog.InviteQrcodeDialog;
import com.ysg.widget.dialog.ListDialog;
import com.ysg.widget.dialog.LoadingDialog;
import com.ysg.widget.dialog.PayDialog;
import com.ysg.widget.dialog.PrivacyDialog;
import com.ysg.widget.dialog.AccostDialog;
import com.ysg.widget.dialog.SVGADialog;
import com.ysg.widget.dialog.ShareDialog;
import com.ysg.widget.dialog.SheetDialog;
import com.ysg.widget.dialog.SignDialog;
import com.ysg.widget.dialog.TicketDialog;
import com.ysg.widget.dialog.VersionDialog;
import com.ysg.widget.dialog.VideoAudioPriceDialog;
import com.ysg.widget.dialog.VipPrivilegeDialog;
import com.ysg.widget.dialog.VipRechargeDialog;
import com.ysg.widget.dialog.entity.DialogEntity;
import com.ysg.widget.dialog.entity.GiftListResult;
import com.ysg.widget.dialog.entity.GiftNumResult;

import java.util.List;

/**
 * 1.选择仓库
 */
public class YDialogUtil {
    private volatile static YDialogUtil mInstance;
    public YDialogUtil(){
    }

    public static YDialogUtil getInstance(){
        if (mInstance == null){
            synchronized (YDialogUtil.class){
                if (mInstance == null){
                    mInstance = new YDialogUtil();
                }
            }
        }
        return mInstance;
    }

    //----------------------------------------------------------------------------
    /**
     * 确认框
     */
    public ConfirmDialog showConfirm(Context context, String content){
        ConfirmDialog dialog = new ConfirmDialog(context, content);
        dialog.show();
        return dialog;
    }

    public ConfirmDialog showConfirm(Context context, String title, String content){
        ConfirmDialog dialog = new ConfirmDialog(context, title, content);
        dialog.show();
        return dialog;
    }

    public ConfirmDialog showConfirm(Context context, String content, String cancelText, String confirmText){
        ConfirmDialog dialog = new ConfirmDialog(context, content, cancelText, confirmText);
        dialog.show();
        return dialog;
    }

    public LoadingDialog showLoading(Context context){
        LoadingDialog dialog = new LoadingDialog(context);
        dialog.show();
        return dialog;
    }

    public ListDialog showList(Context context, String[] items){
        return showList(context, null, items);
    }

    public ListDialog showList(Context context, String title, String[] items){
        ListDialog dialog = new ListDialog(context, title, items);
        dialog.show();
        return dialog;
    }

    public ListDialog showList(Context context, List<DialogEntity> items){
        return showList(context, null, items);
    }

    public ListDialog showList(Context context, String title, List<DialogEntity> items){
        ListDialog dialog = new ListDialog(context, title, items);
        dialog.show();
        return dialog;
    }

    public SheetDialog showSheet(Context context, String[] items){
        SheetDialog dialog = new SheetDialog(context, items);
        dialog.show();
        return dialog;
    }

    public void showDialogDate(Activity context, StringCallback callback) {
        DatePicker picker = new DatePicker(context);
        DateWheelLayout wheelLayout = picker.getWheelLayout();
        wheelLayout.setRange(DateEntity.target(YTimeUtil.getTodayDateByYear(-80)), DateEntity.target(YTimeUtil.getTodayDateByYear(-18)), DateEntity.target(YTimeUtil.getTodayDateByYear(-18)));
        picker.getWheelLayout().setResetWhenLinkage(false);
        picker.setOnDatePickedListener(new OnDatePickedListener() {
            @Override
            public void onDatePicked(int year, int month, int day) {
                StringBuffer sb = new StringBuffer();
                sb.append(year).append("-");
                if (month < 10){
                    sb.append(0);
                }
                sb.append(month).append("-");
                if (day < 10){
                    sb.append(0);
                }
                sb.append(day);
                if (callback != null){
                    callback.onResult(sb.toString());
                }
            }
        });
        picker.show();
    }

    public void showDialogDateTime(Activity context, StringCallback callback) {
        DatimePicker picker = new DatimePicker(context);
        picker.setOnDatimePickedListener(new OnDatimePickedListener() {
            @Override
            public void onDatimePicked(int year, int month, int day, int hour, int minute, int second) {
                StringBuffer sb = new StringBuffer();
                sb.append(year).append("-");
                if (month < 10){
                    sb.append(0);
                }
                sb.append(month).append("-");
                if (day < 10){
                    sb.append(0);
                }
                sb.append(day);

                sb.append(" ");
                if (hour < 10){
                    sb.append(0);
                }
                sb.append(hour).append(":");
                if (minute < 10){
                    sb.append(0);
                }
                sb.append(minute).append(":");
                if (second < 10){
                    sb.append(0);
                }
                sb.append(second);
                if (callback != null){
                    callback.onResult(sb.toString());
                }
            }
        });
        picker.show();
    }

    /**
     * 守护
     */
    public GuardDialog showGuard(Context context, String pic, String nickName, String count){
        GuardDialog dialog = new GuardDialog(context, pic, nickName, count);
        dialog.show();
        return dialog;
    }

    public GiftDialog showGift(Context context, GiftListResult data, GiftNumResult giftNum){
        GiftDialog dialog = new GiftDialog(context, data, giftNum);
        dialog.show();
        return dialog;
    }

    public PayDialog showPay(Context context, String price){
        PayDialog dialog = new PayDialog(context, price);
        dialog.show();
        return dialog;
    }

    /**
     * vip充值
     */
    public VipRechargeDialog showVipRecharge(Context context){
        VipRechargeDialog dialog = new VipRechargeDialog(context);
        dialog.show();
        return dialog;
    }
    /**
     *
     */
    public void showNoDiamond(Context context, NoDiamondEnum noDiamondEnum, boolean hasDiamond){
        switch (noDiamondEnum){
            case text:
                VipRechargeDialog dialog = new VipRechargeDialog(context, hasDiamond);
                dialog.show();
                break;
            case gift:
                DiamondRechargeDialog dialog2 = new DiamondRechargeDialog(context);
                dialog2.show();
                break;
            case call:
                if (YUserUtil.isVip()){
                    DiamondRechargeDialog dialog3 = new DiamondRechargeDialog(context);
                    dialog3.show();
                }else{
                    VipRechargeDialog dialog4 = new VipRechargeDialog(context);
                    dialog4.show();
                }
                break;
        }
    }
    /**
     * SVGA动画
     */
    public SVGADialog showSVGA(Context context, String url){
        SVGADialog dialog = new SVGADialog(context, url);
        dialog.show();
        return dialog;
    }
    /**
     * 打电话：语音通话，视频通话
     */
    public CallDialog showCall(Context context){
        CallDialog dialog = new CallDialog(context);
        dialog.show();
        return dialog;
    }
    /**
     * 语音价格，视频价格
     */
    public VideoAudioPriceDialog showAudioVideoPrice(Context context, String pic, String audioPrice, String videoPrice){
        VideoAudioPriceDialog dialog = new VideoAudioPriceDialog(context, pic, audioPrice, videoPrice);
        dialog.show();
        return dialog;
    }
    /**
     * 亲密度礼物
     */
    public IntimacyGiftDialog showIntimacyGift(Context context, String intimacyValue){
        IntimacyGiftDialog dialog = new IntimacyGiftDialog(context, intimacyValue);
        dialog.show();
        return dialog;
    }

    /**
     * 签到
     */
    public SignDialog showSign(Context context, SignResult data){
        SignDialog dialog = new SignDialog(context, data);
        dialog.show();
        return dialog;
    }
    /**
     * 分享
     */
    public ShareDialog showShare(Context context){
        ShareDialog dialog = new ShareDialog(context);
        dialog.show();
        return dialog;
    }
    /**
     * 邀请二维码
     */
    public InviteQrcodeDialog showInviteQrcode(Context context){
        InviteQrcodeDialog dialog = new InviteQrcodeDialog(context);
        dialog.show();
        return dialog;
    }
    /**
     * 版本更新
     */
    public VersionDialog showVersion(Context context, VersionEntity entity, int appVersion){
        VersionDialog dialog = new VersionDialog(context, entity);
        String version = entity.getVerint();
        try {
            if (Integer.valueOf(version)>appVersion){
                dialog.show();
            }
        }catch (Exception e){
        }
        return dialog;
    }

    /**
     * 今日缘分
     */
    public AccostDialog showRandomUser(Context context, List<UserResult> list){
        AccostDialog dialog = new AccostDialog(context, list);
        dialog.show();
        return dialog;
    }

    /**
     * 修改头像
     */
    public AvatarEditDialog showAvatarEdit(Context context){
        AvatarEditDialog dialog = new AvatarEditDialog(context);
        dialog.show();
        return dialog;
    }
    /**
     * 门票
     */
    public TicketDialog showTicket(Context context, TicketPriceEntity entity){
        TicketDialog dialog = new TicketDialog(context, entity);
        dialog.show();
        return dialog;
    }

    /**
     * 首次：隐私政策
     */
    public PrivacyDialog showPrivacy(Context context){
        PrivacyDialog dialog = new PrivacyDialog(context);
        dialog.show();
        return dialog;
    }

    /**
     * vip特权
     */
    public VipPrivilegeDialog showVipPrivilege(Context context, String type){
        VipPrivilegeDialog dialog = new VipPrivilegeDialog(context, type);
        dialog.show();
        return dialog;
    }
    /**
     * 聊天常用语
     */
    public ExpressionDialog showExpression(Context context, List<ExpressionEntity> list){
        ExpressionDialog dialog = new ExpressionDialog(context, list);
        dialog.show();
        return dialog;
    }











}
